package com.hongdee.scm.provideCompany.controller;

import com.hongdee.base.entity.ResultEntity;
import com.hongdee.scm.provideCompany.entity.TScmProvideCompany;
import com.hongdee.scm.provideCompany.service.ITScmProvideCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/15.
 */
@RestController
@RequestMapping("/scm/provideCompany")
public class TScmProvideCompanyController {

    @Autowired
    private ITScmProvideCompanyService itScmProvideCompanyService;

    /**
     * 新增或编辑
     * @param uid
     * @param token
     * @param tScmProvideCompany
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultEntity save(@RequestParam(name = "uid", defaultValue = "0") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestBody TScmProvideCompany tScmProvideCompany)
    throws Exception{

        this.itScmProvideCompanyService.saveOrUpdate(tScmProvideCompany,uid);
        ResultEntity res = new ResultEntity();
        res.setSuccess(true);
        res.setMsg("操作成功！");
        return res;
    }

    /**
     * 单条查询
     * @param uid
     * @param token
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/info")
    @ResponseBody
    public ResultEntity info(@RequestParam(name = "uid", defaultValue = "0") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "id", defaultValue = "") String id)
            throws Exception{

        Map map = this.itScmProvideCompanyService.info(id,uid);
        ResultEntity res = new ResultEntity();
        res.setData(map);
        res.setSuccess(true);
        res.setMsg("查询成功！");
        return res;
    }

    /**
     * 启用禁用
     * @param uid
     * @param token
     * @param id
     * @param status
     * @return
     * @throws Exception
     */
    @RequestMapping("/startOrStop")
    @ResponseBody
    public ResultEntity startOrStop(@RequestParam(name = "uid", defaultValue = "0") String uid,
                                    @RequestParam(name = "token", defaultValue = "") String token,
                                    @RequestParam(name = "id", defaultValue = "") String id,
                                    @RequestParam(name = "status", defaultValue = "") String status)
            throws Exception{

        this.itScmProvideCompanyService.startOrStop(id,status,uid);
        ResultEntity res = new ResultEntity();
        res.setSuccess(true);
        res.setMsg("操作成功！");
        return res;
    }

    /**
     * 查询
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/page")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "start", defaultValue = "0") String start,
                    @RequestParam(name = "limit", defaultValue = "50") String limit,
                    @RequestBody Map data) throws Exception {

        Map map = this.itScmProvideCompanyService.queryCompany(data,uid,start,limit);
        map.put("success", true);
        map.put("msg", "分页查询成功！");
        return map;
    }

    /**
     * 下拉列表
     * @param uid
     * @param token
     * @param type
     * @return
     * @throws Exception
     */
    @RequestMapping("/combo")
    @ResponseBody
    public List<Map> combo(@RequestParam(name = "uid", defaultValue = "") String uid,
                           @RequestParam(name = "token", defaultValue = "") String token,
                           @RequestParam(name = "type", defaultValue = "") String type
      ) throws Exception {

        return this.itScmProvideCompanyService.combo(uid,type);
    }

}
